<template>
  <div>
    <!-- <svg>
      <use xlink:href="#icon-404" />
    </svg> -->

    <svg-icon v-if="isFull" class="myicon" icon-class="exit-fullscreen" @click="toggle" />
    <svg-icon v-else class="myicon" icon-class="fullscreen" @click="toggle" />
  </div>
</template>

<script>
// 装包 => 导包 => 调用方法
import ScreenFull from 'screenfull'
// ScreenFull.isEnabled => 判断全屏能否使用
// ScreenFull.toggle() => 全屏/退出全屏
export default {
  name: 'ScreenFull',
  data() {
    return {
      isFull: false // 记录当前全屏状态
    }
  },
  methods: {
    toggle() {
      // 全屏
      if (ScreenFull.isEnabled) {
        // 能用
        ScreenFull.toggle()
        this.isFull = !this.isFull
      } else {
        // 不能用
        this.$message.error('很遗憾, 请更新一下浏览器...')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.myicon {
  fill: white;
  cursor: pointer;
}

</style>
